#include "ServerModel.h"
int CServerModel::mainVer=1;
CServerModel::CServerModel(void)
{
    m_mainVerion=mainVer;
    m_releaseNo=0;
    m_subVersion=0;
    m_ServerDirectory = new CServiceServerDirectory;
    if (m_ServerDirectory == NULL)
    {
        printf("Load CServiceServerDirectory Error\n");
        return;
    }
    m_LogicDeviceDirectory = new CServiceGetLogicDeviceDirectory;
    if (m_LogicDeviceDirectory == NULL)
    {
        printf("Load CServiceGetLogicDeviceDirectory Error\n");
        return;
    }
    m_LogicNodeDirectory = new CServiceGetLogicNodeDirectory;
    if (m_LogicNodeDirectory == NULL)
    {
        printf("Load CServiceGetLogicNodeDirectory Error\n");
        return;
    }
    m_DataDefinition = new CServiceGetDataDefinition;
    if (m_DataDefinition == NULL)
    {
        printf("Load CServiceGetDataDefinition Error\n");
        return;
    }
    m_DataValues = new CServiceGetDataValues;
    if (m_DataValues == NULL)
    {
        printf("Load CServiceGetDataValues Error\n");
        return;
    }
    m_DataDirectory = new CServiceGetDataDirectory;
    if (m_DataDirectory == NULL)
    {
        printf("Load CServiceGetDataDirectory Error\n");
        return;
    }
    m_GetDataSetDirectory=new CServiceGetDataSetDirectory;
    if (m_GetDataSetDirectory==NULL)
    {
        printf("Load CServiceGetDataSetDirectory Error\n");
        return;
    }
    m_GetDataSetValues=new CServiceGetDataSetValues;
    if (m_GetDataSetValues==NULL)
    {
        printf("Load CServiceGetDataSetValues Error\n");
        return;
    }
}

CServerModel::~CServerModel(void)
{
    delete m_ServerDirectory;
    m_ServerDirectory=NULL;
    delete m_LogicDeviceDirectory;
    m_LogicDeviceDirectory=NULL;
    delete m_LogicNodeDirectory;
    m_LogicNodeDirectory=NULL;
    delete m_DataValues;
    m_DataValues=NULL;
    delete m_DataDirectory;
    m_DataDirectory=NULL;
    delete m_DataDefinition;
    m_DataDefinition=NULL;
    delete m_GetDataSetDirectory;
    m_GetDataSetDirectory=NULL;
    delete m_GetDataSetValues;
    m_GetDataSetValues=NULL;
}
void CServerModel::SetVerion(int mainVerion,int subVersion,int releaseNo)
{
    m_mainVerion=mainVerion;
    m_releaseNo=releaseNo;
    m_subVersion=subVersion;
    //m_DataDirectory->SetVerion(mainVerion,subVersion,releaseNo);
    //m_DataDefinition->SetVerion(mainVerion,subVersion,releaseNo);
}
void CServerModel::GetVersion()
{
    printf("Version:%d.%d.%d\n",m_mainVerion,m_subVersion,m_releaseNo);
}
void CServerModel::AppSleep(int ms)
{
    QTime t;
    t.start();
    while(t.elapsed()<ms)
    {
        QCoreApplication::processEvents();
    }
}
BOOL CServerModel::SetTreeItem(QTreeWidgetItem *treeItem)
{
    m_DataDefinition->SetTreeItem(treeItem);
    m_DataValues->SetTreeItem(treeItem);
    return  TRUE;
}
BOOL CServerModel::SetXml(QDomNode xml)
{
    //m_DataDefinition->SetXml(xml);
    return TRUE;
}
BOOL CServerModel::SetDataSetItem(QTreeWidgetItem *treeItem)
{
    m_GetDataSetValues->SetTreeItem(treeItem);
    m_GetDataSetDirectory->SetDataSetItem(treeItem);
}
BOOL CServerModel::ProcGetServerDirectory(int iClass, CMTree & tree)
{
    return m_ServerDirectory->OnGetServerDirectory(iClass, tree);
}
BOOL CServerModel::ServerDirectory(QStringList *ServerDirectory)
{
    return m_ServerDirectory->ServerDirectory(ServerDirectory);
}
BOOL CServerModel::LogicNodeDirectory(QStringList *LogicNodeDirectory)
{
    return m_LogicNodeDirectory->LogicNodeDirectory(LogicNodeDirectory);
}
BOOL CServerModel::ProcGetLogicDeviceDirectory(const char * szLDRef,
        CMTree & tree)
{
    return m_LogicDeviceDirectory->OnGetLogicDeviceDirectory(szLDRef, tree);
}
BOOL CServerModel::LogicDeviceDirectory(QStringList *LogicDeviceDirectory)
{
    return m_LogicDeviceDirectory->LogicDeviceDirectory(LogicDeviceDirectory);
}
BOOL CServerModel::ProcGetLogicNodeDirectory(const char * szLNRef, int iClass,
        CMTree & tree)
{
    return m_LogicNodeDirectory->OnGetLogicNodeDirectory(szLNRef, iClass, tree);
}
BOOL CServerModel::ProcGetDataValues(const char * szDataRef, CMTree & tree)
{
    return m_DataValues->OnGetDataValues(szDataRef,tree);
}
BOOL CServerModel::ProcGetDataDirectory(const char * szDataRef, CMTree & tree)
{
    return m_DataDirectory->OnGetDataDirectory(szDataRef,tree);
}
BOOL CServerModel::ProcGetDataDefinition(const char * szDataRef, CMTree & tree)
{
    return m_DataDefinition->OnGetDataDefinition(szDataRef, tree);
}
BOOL CServerModel::ProcGetDataSetDirectory(const char * szDataSetRef, CMTree & tree)
{
    return m_GetDataSetDirectory->OnGetDataSetDirectory(szDataSetRef,tree);
}
BOOL CServerModel::ProcGetDataSetValues(const char * szDataSetRef, CMTree & tree)
{
    return m_GetDataSetValues->OnGetDataSetValues(szDataSetRef,tree);
}
